<?php
include_once ('../global.php');
require_once 'css/mydata/aliyun-oss-php-sdk/autoload.php';
use OSS\Core\OssException;
use OSS\OssClient;
$get_data=$_REQUEST;
$mt_id=intval($get_data['mt_id']);
$user_id=intval($get_data['user_id']);



//资格赛 https://scoringchina.oss-cn-beijing.aliyuncs.com/bmwjunior/videos/qua/
//大师赛  https://scoringchina.oss-cn-beijing.aliyuncs.com/bmwjunior/videos/master/
//锦标赛 https://scoringchina.oss-cn-beijing.aliyuncs.com/bmwjunior/videos/champion/
// 阿里云账号AccessKey
$accessKeyId = "LTAI5tLjRRGStbtE2BnZkRFJ";
$accessKeySecret = "HWPzzmyqRL9jxKXb2UOk37BXayV1Fc";

$endpoint = "oss-cn-beijing.aliyuncs.com";
$bucket = "scoringchina";
$host = "https://scoringchina.oss-cn-beijing.aliyuncs.com";
$file = $_FILES['file']; // 假设是通过表单上传的文件
$filePath = $file['tmp_name'];

$filename = $file['name']; // 文件名
$ext = pathinfo($filename, PATHINFO_EXTENSION); // 获取文件后缀名
// 填写Object完整路径
if($mt_id==4578){
    $object = "bmwjunior/videos/qua/bmw_".$user_id."_".$mt_id.".".$ext;
}
if($mt_id==4400){
    $object = "bmwjunior/videos/master/bmw_".$user_id."_".$mt_id.".".$ext;
}
if($mt_id==4579){
    $object = "bmwjunior/videos/champion/bmw_".$user_id."_".$mt_id.".".$ext;
}
// 填写本地文件的完整路径
//$filePath = "D:\\localpath\\examplefile.txt";


$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);

$ossClient->uploadFile($bucket, $object, $filePath);

$url = "{$host}/{$object}";
$sql = "SELECT * FROM bmw_player_video where pl_id='{$user_id}' and mt_id='{$mt_id}'";
$info= $db->SelectSQL($sql);
$act_datetime=date("Y-m-d H:i:s");
if($info){//更新
    $sql=" update bmw_player_video set video='{$url}',update_time='{$act_datetime}' where pl_id='{$user_id}' and mt_id='{$mt_id}'";
    $db->ExecuteSQL($sql);
}else{//插入
    $sql=" insert into bmw_player_video(pl_id,mt_id,video,create_time,update_time) values('{$user_id}','{$mt_id}','{$url}','{$act_datetime}','{$act_datetime}');";
    $db->ExecuteSQL($sql);
}
echo json_encode(['code'=>1]);
exit;
